package com.alliky.classify.ui.viewmodel

import androidx.lifecycle.viewModelScope
import androidx.paging.ExperimentalPagingApi
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.alliky.core.base.BaseViewModel
import com.rrc.common.entity.CategoryVO
import com.rrc.common.entity.GoodsVO
import com.alliky.core.net.StateLiveData
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch

/**
 * ================================================
 * @Description: 描述
 * @Author: wxianing
 * @Date: 2023/1/5 15:53
 * ================================================
 */
@ExperimentalPagingApi
class ClassifyViewModel : BaseViewModel() {

    var categoryLiveData = StateLiveData<List<CategoryVO>>()

    fun getCategoryData(params: HashMap<String, String>) {
        viewModelScope.launch {
            repo.getCategoryData(params, categoryLiveData)
        }
    }

    fun hotGoodsPagingFlow(): Flow<PagingData<GoodsVO>> =
        repo.getHotGoods().cachedIn(viewModelScope)

    fun categoryDataFlow(): Flow<PagingData<CategoryVO>> =
        repo.getCategoryData2().cachedIn(viewModelScope)
}